package service.impl;

import dao.ProductDao;
import dao.impl.ProductDaoimpl;
import pojo.PageBean;
import pojo.Product;
import service.ProductService;

import java.sql.SQLException;
import java.util.List;

/**
 * @author LiangHaiBo
 * @version 1.0
 * @date 2021.9.7 下午 15:46
 */
public class ProductServiceimpl implements ProductService {
    /**
     * 最新商品
     * @return
     */
    @Override
    public List<Product> GetnewProdect() {
        try {
            ProductDao productDao = new ProductDaoimpl();
            List<Product> newlist = productDao.selectnewProdect();
            if(newlist != null){
                return newlist;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
       }

    /**
     * 热门图片
     * @return
     */
    @Override
    public List<Product> GethotProdect() {
        try {
            ProductDao productDao = new ProductDaoimpl();
            List<Product> hotlist = productDao.selecthotProdect();
            if(hotlist != null){
                return hotlist;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Product getProductById(String pid) {

        try {
            ProductDao productDao = new ProductDaoimpl();
            Product product = productDao.selectProductById(pid);
            if(product != null){
                return product;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    public PageBean<Product> getProductByPage(int currentPage, int pageSize, String cid) {

        try {
            ProductDao productDao = new ProductDaoimpl();

            List<Product> list = productDao.selectProductByPage(currentPage,pageSize,cid);
            int totalCount = productDao.selectTotalCount(cid);

            return new PageBean<Product>(currentPage,pageSize,totalCount,list);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
